package com.jdew.thkj.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.jdew.thkj.R;
import com.jdew.thkj.bean.CountyAreaBean;
import com.jdew.thkj.utils.ZXingUtils;

import java.util.ArrayList;
import java.util.List;

public class MyErAdapter extends BaseAdapter{
	private List<String> list;
	private LayoutInflater inflater;
	private Context context;

	public MyErAdapter(Context context, List<String> list) {
		this.context=context;
		this.list = list;
		this.inflater = LayoutInflater.from(context);
	}

	public List<String> getList() {
		return list;
	}

	public void setList(List<String> list) {
		this.list = list;
		notifyDataSetChanged();
	}

	@Override
	public int getCount() {
		return list == null ? 0 : list.size();
	}

	@Override
	public String getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		//加载布局为一个视图
		View view = inflater.inflate(R.layout.share_item, null);
		ImageView pic = (ImageView) view.findViewById(R.id.pic);
		ImageView ercode = (ImageView) view.findViewById(R.id.ercode);
		Glide.with(context).load(list.get(position)).into(pic);
		try {
			Bitmap shareBitmap = ZXingUtils.createQRImage("hahaha", 300, 300);//自己写的方法
			if (shareBitmap != null) {
				ercode.setImageBitmap(shareBitmap);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return view;
	}
}